package com.mca.framework.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class DemoDistinct1 {
    public static void main(String[] args) {
        //对数据模2后结果去重
        List<Integer> numberList = Arrays.asList(1, 2, 3, 4, 1, 2, 3, 4);
        List<Integer> list = demo3(numberList);
        System.out.println(list);
    }


    /**
     * 通过stream中的distinct完成数据去重
     * @param numberList
     * @return
     */
    public static List<Integer> demo3(List<Integer> numberList){
        List<Integer> result = numberList.stream()
                .filter(n -> n % 2 == 0)
                .distinct()
                .collect(Collectors.toList());
        return result;
    }
}
